<!-- 退场结算 -->
<template>
	<view>
		<bg-tab :current="current" :tabs="tabs" @tab-change="tabChange"></bg-tab>
		<view class="m-3">
			<scroll-view :scroll-y="true" class="scroll-block" refresher-background="transparent"
				refresher-enabled="true" :refresher-triggered="triggered" @refresherrefresh="onRefresh">
				<template v-if="dataList.length>0">
					<view v-for="i in dataList" :key="i.id" class="bt-block py24px30" @tap="gotoDetail(i)">
						<view class="flex">
							<view class="flex-1">
								<bg-desc label="申请人" :value="i.userName"></bg-desc>
								<!-- <bg-desc label="合计金额" :value="i.amount"></bg-desc> -->
								<bg-desc label="合计金额" :value="i.actualAmount"></bg-desc>
								<bg-desc label="项目名称" :valueStyle="{width:'150px'}" :value="i.projectName"></bg-desc>
								<bg-desc label="提交时间" :valueStyle="{width:'150px'}" :value="i.createTime"></bg-desc>
							</view>
							<view class="flex align-center">
								<u--image v-if="i.status==1" width="148rpx" height="148rpx"
									src="/static/images/ui/salary/wait.png"></u--image>
								<u--image v-if="i.status==2" width="148rpx" height="148rpx"
									src="/static/images/ui/salary/pass.png"></u--image>
								<u--image v-if="i.status==3" width="148rpx" height="148rpx"
									src="/static/images/ui/salary/reject.png"></u--image>
							</view>
						</view>
					</view>
				</template>
				<u-empty v-if="dataList.length==0&&!triggered"></u-empty>
			</scroll-view>

		</view>


	</view>
</template>

<script>
	import {
		settleList,
		settleLeaderList,
		leaderAuditbatch,
		managerAuditbatch,
		canSettle
	} from '../../../api/retire'
	export default {
		onNavigationBarButtonTap() {
			// if (this.$auth.hasRole('worker')) {
			if (this.$auth.hasRoleOr(['team', 'worker'])) {
				canSettle({}).then(res => {
					console.log('res', res);
					if (res.code == 200) {
						uni.navigateTo({
							url: "/pages/common/sms/sms?title=退场结算&btnTitle=申请退场结算&targetUrl=/pages/salary/settlement/settlement"
						})
					}

				})

			} else {
				this.$modal.msg("本功能仅限工人和班组管理员使用")
			}

		},
		data() {
			return {
				triggered: false,
				_freshing: false,
				dataList: [],
				params: {
					status: 1,
					pageNum: 1,
					pageSize: 10
				},
				total: 0,
				current: 0,
				tabs: [
					"待审批", "审批通过", "审批未通过"
				],
				isShowAuditBtn: false,
				allAuditList: [],
				auditTotal: 0,
				show: false,
			}
		},
		onLoad(options) {
			this.getData()
			this.getUserInfo()
			uni.$on("refresh-settle", () => {
				this.params.pageNum = 1
				this.dataList = []
				this.getData()
			})
		},
		methods: {
			getUserInfo() {
				if (this.$auth.hasRoleOr(["team", "project"])) {
					this.isShowAuditBtn = true
					settleLeaderList({
						status: 1,
						pageNum: 1,
						pageSize: 10000
					}).then(res => {

						let data = res.data.rows
						this.auditTotal = res.data.total
						let arr = []
						data.map((item) => {
							arr.push({
								id: item.id,
								status: 2
							})
							return item
						})
						this.allAuditList = arr
					})
				}

			},
			async onRefresh() {
				if (this._freshing) return;
				this._freshing = true;
				if (!this.triggered) this.triggered = true;

				this.params.pageNum = 1
				this.dataList = []
				await this.getData()

				setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
				}, 2000)
			},
			getData() {
				let method = settleList
				if (this.$auth.hasRole("team") || this.$auth.hasRole("project")) {
					method = settleLeaderList
				}
				method(this.params).then(res => {
					this.dataList = [...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
			},
			tabChange(idx) {
				this.current = idx
				this.params.status = idx + 1
				this.params.pageNum = 1
				this.dataList = []
				this.getData()
			},
			gotoDetail(i) {
				uni.navigateTo({
					url: "/pages/salary/settlement/detail?id=" + i.id
				})
			},
			getRetireLeaderList() {
				method(this.params).then(res => {
					this.dataList = [...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
			},
			confirmModal() {
				let method = ''
				if (this.$auth.hasRole("team")) {
					method = leaderAuditbatch
				} else if (this.$auth.hasRole("project")) {
					method = managerAuditbatch
				}
				method(this.allAuditList).then(res => {
					this.show = false;
				})
			},
			closeModal() {
				this.show = false;
			},
			allAudit() {
				this.show = true;
			}
		}
	}
</script>

<style lang="scss">
	.footer_contain {
		width: 100%;
		height: 170rpx;
		background: #ffffff;
		box-shadow: 0rpx 0rpx 12rpx 0rpx #ebebeb;
		position: fixed;
		bottom: 0;
		padding: 30rpx 24rpx 0;
		box-sizing: border-box;

		.footer_contain_text {
			width: 720rpx;
			height: 90rpx;
			background: #d7000f;
			border-radius: 8rpx;
			font-size: 30rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			text-align: center;
			color: #ffffff;
			line-height: 90rpx;
		}
	}
</style>